package wng.su;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.app.Notification.Builder;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.graphics.Bitmap.Config;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Icon;
import android.media.AudioAttributes;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.Build.VERSION;
import android.text.TextPaint;

public class S extends Service {
   static long[] i = new long[]{1024000L, 1048576000L, Long.MAX_VALUE};
   static double[] j = new double[]{1024.0D, 1048576.0D, 1.073741824E9D};
   static String[] k = new String[]{"K", "M", "G"};
   Handler a = new Handler();
   Runnable b = new Runnable() {
      public void run() {
         S.this.a();
         S.this.a.postDelayed(this, 1000L);
      }
   };
   NotificationManager c;
   Builder d;
   Bitmap e;
   Canvas f;
   TextPaint g;
   float h = 25.0F;
   long l = 0L;
   long m = 0L;

   public static String a(long var0) {
      if (var0 < 1000L) {
         if (var0 < 100L) {
            StringBuilder var9 = new StringBuilder();
            Object[] var10 = new Object[]{var0};
            return var9.append(String.format("% 3d", var10)).append("B").toString();
         } else {
            return var0 + "B";
         }
      } else {
         for(int var2 = 0; var2 < 3; ++var2) {
            if (var0 < i[var2]) {
               double var3 = (double)var0 / j[var2];
               String var6;
               if (var3 < 10.0D) {
                  Object[] var8 = new Object[]{var3};
                  var6 = String.format("%.1f", var8);
               } else if (var3 < 100.0D) {
                  Object[] var7 = new Object[]{var3};
                  var6 = String.format(" %.0f", var7);
               } else {
                  Object[] var5 = new Object[]{var3};
                  var6 = String.format("%.0f", var5);
               }

               return var6 + k[var2];
            }
         }

         return "wtfk";
      }
   }

   public Notification a(long var1, long var3) {
      if (this.d == null) {
         if (VERSION.SDK_INT > 26) {
            NotificationChannel var7 = new NotificationChannel("wangsu", "网速状态栏", 3);
            var7.setLockscreenVisibility(-1);
            if (VERSION.SDK_INT >= 29) {
               var7.setAllowBubbles(false);
            }

            var7.enableLights(false);
            var7.enableVibration(false);
            var7.setSound((Uri)null, (AudioAttributes)null);
            this.c.createNotificationChannel(var7);
            this.d = new Builder(this, "wangsu");
         } else {
            this.d.setPriority(0);
            this.d.setVibrate((long[])null);
            this.d.setSound((Uri)null);
            this.d.setLights(0, 0, 0);
         }

         this.d.setOngoing(true);
      }

      this.d.setContentText("\ud83d\udc46 " + a(var3) + "/s  \ud83d\udc47 " + a(var1) + "/s");
      this.b(var1, var3);
      this.d.setSmallIcon(Icon.createWithBitmap(this.e));
      return this.d.build();
   }

   public void a() {
      Notification var1 = this.a(TrafficStats.getTotalRxBytes() - this.l, TrafficStats.getTotalTxBytes() - this.m);
      this.c.notify(-1010302975, var1);
      this.l = TrafficStats.getTotalRxBytes();
      this.m = TrafficStats.getTotalTxBytes();
   }

   void b(long var1, long var3) {
      this.f.drawColor(0, Mode.CLEAR);
      String var5 = a(var3);
      this.f.drawText(var5, 31.0F, 31.0F, this.g);
      String var6 = a(var1);
      this.f.drawText(var6, 31.0F, 32.0F + this.h, this.g);
   }

   public IBinder onBind(Intent var1) {
      return null;
   }

   public void onCreate() {
      super.onCreate();
      this.c = (NotificationManager)this.getSystemService("notification");
      this.e = Bitmap.createBitmap(64, 64, Config.ARGB_8888);
      this.f = new Canvas(this.e);
      this.g = new TextPaint();
      this.g.setAntiAlias(true);
      this.g.setTextSize(this.h);
      this.g.setColor(-1);
      this.g.setTypeface(Typeface.MONOSPACE);
      this.g.setTextAlign(Align.CENTER);
      this.g.setStyle(Style.FILL);
      this.g.setFakeBoldText(true);
   }

   public int onStartCommand(Intent var1, int var2, int var3) {
      this.a.removeCallbacks(this.b);
      this.a.postDelayed(this.b, 1000L);
      this.l = TrafficStats.getTotalRxBytes();
      this.m = TrafficStats.getTotalTxBytes();
      this.startForeground(-1010302975, this.a(0L, 0L));
      return 1;
   }
}
